package model;

import shared.Buffer;

public abstract class Obtainer<T> implements Runnable {

	private final QuantifiedComponent component;
	private final Buffer<T> resultBuffer;

	public QuantifiedComponent getComponent() {
		return component;
	}
	
	/**
	 * Constructor of {@link Obtainer}.
	 * @param component is the {@link QuantifiedComponent} of which something is supposed to be obtained in run().
	 * @param resultBuffer is the {@link Buffer} where the result is put into.
	 */
	public Obtainer(final QuantifiedComponent component, final Buffer<T> resultBuffer) {
		this.component = component;
		this.resultBuffer = resultBuffer;
	}

	
	@Override
	public void run() {
		this.resultBuffer.put(this.calculate());
	}

	/**
	 * Provides an object of the type T.
	 */
	protected abstract T calculate();
}
